package com.sky.mapper;
import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Description TODO
 * @Author itheima
 * @Date 2023-07-19 17:55
 */
@Mapper
public interface ShoppingCartMapper {
    /**
     * 根据菜品口味查找购物车数据
     * @param shoppingCart
     * @return
     */
    @Select("select  * from shopping_cart where user_id = #{userId}" +
            " and dish_id = #{dishId} or dish_flavor =#{dishFlavor}")
    ShoppingCart gedishid(ShoppingCart shoppingCart);

    /**
     * 根据套餐查找购物车数据
     * @param shoppingCart
     * @return
     */
    @Select("select  * from shopping_cart where user_id = #{userId}" +
            " and setmeal_id = #{setmealId} ")
    ShoppingCart getsettmealid(ShoppingCart shoppingCart);

    /**
     * 修改购物车指定类型的数量
     * @param abshoppingCart
     */
    @Update("update shopping_cart set number = #{number} where id=#{id}")
    void updateNumber(ShoppingCart abshoppingCart);

    /**
     * 添加购物车的数据
     * @param abshoppingCart
     */
    @Insert("insert into shopping_cart " +
            "values(null,#{name},#{image},#{userId},#{dishId},#{setmealId}," +
            "#{dishFlavor},#{number},#{amount},#{createTime})")
    void add(ShoppingCart abshoppingCart);

    /**
     * 根据用户id查询购物车数据
     * @param userid
     * @return
     */
    @Select("select * from shopping_cart where user_id=#{userId} order by create_time ")
    List<ShoppingCart> findByUserId(Long userid);

    /**
     * 清空购物车
     * @param userid
     */
    @Delete("delete from shopping_cart where user_id=#{userId}")
    void clean(Long userid);

    /**
     * 根据id删除购物车数据
     * @param id
     */
  @Delete("delete from shopping_cart where id=#{id}")
    void delete(Long id);
}
